﻿@using System.Web.Mvc;
@using System.Web.Mvc.Html;
@using System.Linq.Expressions;
@functions
{
    public static HelperResult ControlFor<TModel, TItem>(HtmlHelper<TModel> html, Expression<Func<TModel, TItem>> expr)
    {
        return RenderControl(html.LabelFor(expr), html.EditorFor(expr), html.ValidationMessageFor(expr));
    }

    public static MvcHtmlString MenuLink(System.Web.Mvc.HtmlHelper helper, string text, string action, string controller)
    {
        var routeData = helper.ViewContext.RouteData.Values;
        var currentController = routeData["controller"];
        var currentAction = routeData["action"];

        if (String.Equals(action, currentAction as string, StringComparison.OrdinalIgnoreCase) && String.Equals(controller, currentController as string, StringComparison.OrdinalIgnoreCase))
        {
            return new MvcHtmlString("<li class='active'>" + helper.ActionLink(text, action, controller).ToString() + "</li>");
        }
        return new MvcHtmlString("<li>" + helper.ActionLink(text, action, controller).ToString() + "</li>");
    }
}

@helper RenderControl(MvcHtmlString label, MvcHtmlString control, MvcHtmlString validationMessage)
{
    <div class="control-group">
        <label class="control-label" for="inputEmail">@label</label>
        <div class="controls">
            @control
        </div>
    </div>
}

@helper Submit(string text)
{
    <div class="control-group">
        <div class="controls">
            <button type="submit" class="btn">@text</button>
        </div>
    </div>
}